﻿using UnityEngine;

public class RopeBezier2Mono : MonoBehaviour
{
    public int UsePointCount = 50;
    public Transform start;
    public Transform midPoint;
    public Transform end;

    public LineRenderer lineRenderer;

    [ContextMenu("立即生成线")]
    public void CreateLine()
    {
        lineRenderer.positionCount = UsePointCount + 1;
        float pointLength = 1 / (float)UsePointCount;
        float add = 0;
        for (int i = 0; i < UsePointCount + 1; i++)
        {
            Vector3 point =  Bezier.Bezier2(start.localPosition, midPoint.localPosition, end.localPosition, add);
            lineRenderer.SetPosition(i, point);
            add += pointLength;
        }  
    }
    public void Update()
    {
        CreateLine();
    }
}

